<template>
  <div class="app-container" :class="{ 'qiankun-microapp': isQiankun }">
    <!-- 简化的微应用布局 -->
    <div class="microapp-layout">
      <router-view v-slot="{ Component }">
        <transition name="fade" mode="out-in">
          <keep-alive>
            <component :is="Component" />
          </keep-alive>
        </transition>
      </router-view>
    </div>

    <!-- 右侧浮动调试工具图标 -->
    <div class="floating-debug-icon" @click="openTokenDebugger">
      <el-icon><Setting /></el-icon>
    </div>

    <!-- Token管理工具弹窗 -->
    <el-dialog
      v-model="showTokenDebugger"
      title="Token 调试工具"
      width="500px"
      :close-on-click-modal="false"
    >
      <TokenDebugger />
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import { computed, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { Setting } from '@element-plus/icons-vue'
import { qiankunWindow } from 'vite-plugin-qiankun/dist/helper'
import { useAuthStore } from './store/auth'
import TokenDebugger from './components/TokenDebugger.vue'

const authStore = useAuthStore()

// 响应式数据
const showTokenDebugger = ref(false)

// 计算属性
const isQiankun = computed(() => qiankunWindow.__POWERED_BY_QIANKUN__)

// 暴露方法给全局使用
const openTokenDebugger = () => {
  showTokenDebugger.value = true
}

// 暴露到全局
if (typeof window !== 'undefined') {
  (window as any).openTokenDebugger = openTokenDebugger
}
</script>

<style>
/* 复用main.css中定义的变量 */
:root {
  --primary-color: var(--el-color-primary);
  --accent-color: var(--el-color-danger);
  --accent-light: var(--el-color-warning);
  --accent-lightest: var(--el-color-success-light-9);
  --background-color: var(--el-bg-color);
  --text-color: var(--el-text-color-primary);
  --text-color-secondary: var(--el-text-color-secondary);
  --border-color: var(--el-border-color);
  --border-color-light: var(--el-border-color-lighter);
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.1);
  --transition-fast: 0.2s ease;
  --transition-normal: 0.3s ease;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

.app-container {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: var(--text-color);
  min-height: 100vh;
  position: relative;
}

/* 微应用环境下的样式 */
.qiankun-microapp {
  padding: 0;
  background-color: transparent;
}

.microapp-layout {
  padding: 0;
  background-color: transparent;
}

/* 右侧浮动调试图标 */
.floating-debug-icon {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 50px;
  height: 50px;
  background: var(--primary-color);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  transition: all var(--transition-fast);
  font-size: 20px;
}

.floating-debug-icon:hover {
  background: var(--accent-color);
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(106, 44, 112, 0.3);
}

/* 页面过渡动画 */
.fade-enter-active,
.fade-leave-active {
  transition: opacity var(--transition-normal);
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}
</style> 